"""
import threading
import time


# 定义一个函数，模拟线程的工作
def worker():
    while True:
        print("Worker is running")
        time.sleep(1)  # 线程休眠1秒钟


# 创建线程对象
t = threading.Thread(target=worker)

# 启动线程
t.start()

# 等待5秒钟，然后停止线程
time.sleep(5)
t.start()
"""

import time, threading
import random

# 假定这是你的银行存款:
balance = 0


def change_it(n):
    # 先存后取，结果应该为0:
    global balance
    balance = balance + n
    balance = balance - n


def run_thread(n):
    for i in range(10):
        change_it(n)


t1 = threading.Thread(target=run_thread, args=(5,))
t2 = threading.Thread(target=run_thread, args=(8,))
t1.start()
t2.start()
t1.join()
t2.join()
print(balance)
